using System.Collections;
using System.Web.Security;
using Concurso.Clases;
using ConcursoCV.UI.Clases;

namespace ConcursoCV.UI.WebUserControls
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for MasterMenuControl.
	/// </summary>
	public class MasterMenuControl : System.Web.UI.UserControl
	{
		protected System.Web.UI.HtmlControls.HtmlGenericControl lblUser;
		protected System.Web.UI.HtmlControls.HtmlGenericControl lblGroup;
		protected System.Web.UI.WebControls.LinkButton lbCerrarSesion;
		protected skmMenu.Menu menu;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				this.lblUser.InnerText = Helper.SecurityHelper.CurrentUserName;
				this.lblGroup.InnerText = RoleConverter.ToConfigurationName( Helper.SecurityHelper.GetRole() );
				
				//Agrego el rol del usuario que esta logueado
				menu.UserRoles.Add( RoleConverter.ToConfigurationName(Helper.SecurityHelper.GetRole()));
				
				menu.DataSource = Server.MapPath("menu.xml");
				menu.HighlightTopMenu = false;
				menu.DataBind();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lbCerrarSesion.Click += new System.EventHandler(this.lbCerrarSesion_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void lbCerrarSesion_Click(object sender, System.EventArgs e)
		{
			FormsAuthentication.SignOut();
			Response.Redirect("login.aspx");		
		}
	}
}
